package com.shtb.wisdom.videotaker

import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.WindowManager
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity

open class BaseActivity: AppCompatActivity() {

    /// 加载对话框对象
    private var loadingDialog: AlertDialog? = null


    /// 显示加载对话框
    fun showLoading(text: String) {

        if (loadingDialog != null) {

            return
        }

        loadingDialog = AlertDialog.Builder(this).setTitle("").setMessage(text).create()
        loadingDialog?.setCancelable(false)
        loadingDialog?.show()
    }

    /// 隐藏加载对话框
    fun hideLoading() {

        if (loadingDialog == null) {

            return
        }

        loadingDialog?.dismiss()

        loadingDialog = null
    }

    override fun onDestroy() {

        super.onDestroy()

        Log.i("wisdom", "${this.javaClass.simpleName} destroyed !!")
    }

    @SuppressLint("SourceLockedOrientationActivity")
    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)

        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

        setStatusBarColor()
    }

    public fun setStatusBarColor() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            val window = window
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        }
    }
}